<?php

namespace App\Repository\Repositories;


use App\Models\StoreBargainUserHelp;
use App\Models\StoreHead;
use App\Models\User;
use App\Repository\RepositoryInterface\PersonalInterface;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use function DI\create;


class PersonalRepositories implements PersonalInterface
{
    /**
     * @param $uid
     * @return array
     * 个人中心
     */
    public function index($uid)
    {
       $user=DB::select('select * from tg_user where uid='.$uid);
       return $user;
    }

    /**
     * @return array
     * 活动列表
     */
    public function articleIndex()
    {
        $article=DB::select('select * from tg_article');
        return $article;
    }


    /**
     * 用户订单
     */

    public function orderUser($uid)
    {
       $order=DB::select('select * from tg_store_order where uid='.$uid);
       return $order;
    }


    /**
     * 团长新增
     */
    public function colonelCreate($param){
        $colonel=StoreHead::create($param);
        return json_encode(['code'=>200,'data'=>$colonel,'msg'=>'成功']);
    }

    /**
     * 分享 根据邀请码查询用户
     * 给用户分享金额
     */
    public function shareUser($share){
        $user=User::where('account',$share)->first();
        $price=$user['now_money']+3;
        //分享成功后 才添加金额
        //这里需要和用户注册对接 以下为模拟数据
        $userShare=User::where('uid',$user['uid'])->update(['now_money'=>$price]);
        if(!$userShare){
            return ['code'=>500,'data'=>'','msg'=>'邀请失败'];
        }else{
            return ['code'=>200,'data'=>$userShare,'msg'=>'邀请成功'];
        }


    }

}
